{% extends "element/saas/base_mini.html" %}

{% block meta_title %}企业多维筛查{% endblock %}

{% block main %}
    <div class="admin-content">
        <div style="padding-top:3px;">
            <div id="toolbar1" class="mini-toolbar" style="padding: 2px 0;">
                <table style="width:100%;">
                    <tr>
                        <td style="width:100%;">
                            <a class="mini-button mini-button-eltext" iconCls="icon-zoomin" plain="true">企业全维筛查系统</a>
                            <span class="separator"></span>
                            <a class="mini-menubutton" iconCls="icon-upload-folder" plain="true"
                               menu="#popupMenu1">视图</a>
                            <a class="mini-button" iconCls="icon-reload" plain="true" onclick="tabreload()">重载标签页</a>
                            <span class="separator"></span>
                            <a class="mini-button" iconCls="icon-report10" plain="true"
                               onclick="elreport('10')">全景版征信报告</a>
                            <a class="mini-button" iconCls="icon-report11" plain="true"
                               onclick="elreport('11')">标准版报告</a>
                            {% if not sitesettings.website_proxy %}
                                <a class="mini-menubutton" iconCls="icon-pdf" plain="true" menu="#popupMenu3">下载报告PDF</a>
                            {% endif %}
                            <a class="mini-menubutton" iconCls="icon-chart_curve" plain="true"
                               menu="#popupMenu4">可视化图谱</a>
                            <a class="mini-menubutton" iconCls="icon-color_swatch" plain="true"
                               menu="#popupMenu5">更多操作</a>
                        </td>
                    </tr>
                </table>
            </div>

            <ul id="popupMenu1" class="mini-menu" style="display:none;">
                <li iconCls="icon-lock" onclick="hidesearch('hide')">隐藏筛选器</li>
                <li iconCls="icon-unlock" onclick="hidesearch('show')">显示筛选器</li>
                <li iconCls="icon-lock" onclick="tableborder('h',false)">隐藏行线</li>
                <li iconCls="icon-unlock" onclick="tableborder('h',true)">显示行线</li>
                <li iconCls="icon-lock" onclick="tableborder('v',false)">隐藏列线</li>
                <li iconCls="icon-unlock" onclick="tableborder('v',true)">显示列线</li>
            </ul>

            <ul id="popupMenu3" class="mini-menu" style="display:none;">
                <li iconCls="icon-pdf" onclick="elreportpdf('10')">全景版PDF</li>
                <li iconCls="icon-pdf" onclick="elreportpdf('11')">标准版PDF</li>
            </ul>

            <ul id="popupMenu4" class="mini-menu" style="display:none;">
                <li iconCls="icon-chart_line" onclick="elchart('2')">专业版关联图</li>
                <li iconCls="icon-chart_organisation" onclick="elchart('1')">基础版关联图</li>
                <li iconCls="icon-vector" onclick="ellifecycle()">生命周期预测</li>
            </ul>
            <ul id="popupMenu5" class="mini-menu" style="display:none;">
                <li iconCls="icon-feed_add" onclick="">关注该企业</li>
                {# 暂时只对内部的人开放 #}
                {% if request.user.id < 42 %}
                    <li iconCls="icon-excel " onclick="downloadSure()">导出本页为Excel</li>
                {% endif %}
            </ul>

            <div style="padding-top:6px;">
                <div id="mainTabs" class="mini-tabs" activeIndex="0" style="width:100%;height:auto;min-height: 800px">
                    <!--Tab 主数据表 -->
                    <div title="企业仓库" name="主数据表" iconCls="icon-table">

                        <form id="form_search" method="post" style="padding:5px 0 15px 2px;margin-bottom: 2px;">
                            <table id="se_table">
                                <tr class="se_tr">
                                    <td class="se_title">企业名称：</td>
                                    <td class="se_input" style="width: 22%;">
                                        <input name="ENTNAME" class="mini-autocomplete" valueField="ENTNAME"
                                               textField="ENTNAME" url="/entmohu/" emptyText="支持模糊查询，支持曾用名"
                                               popupEmptyText="查无数据" loadingText="加载中..." vtype="rangeLength:2,100">
                                    </td>
                                    <td style="width: 2%;"></td>
                                    <td class="se_title">注册号：</td>
                                    <td class="se_input" style="width: 22%;">
                                        <input name="REGNO" class="mini-textbox" emptyText="完整注册号"
                                               vtype="rangeLength:8,32">
                                    </td>
                                    <td style="width: 2%;"></td>
                                    <td class="se_title">总营收：</td>
                                    <td class="se_range" style="width: 22%;">
                                        <input name="revenue1" class="mini-textbox" style="width:45%;float:left;"
                                               vtype="range:0,1000000" emptyText="万元"/>
                                        <span class="se_line">一</span>
                                        <input name="revenue2" class="mini-textbox" style="width:45%;float:left;"
                                               vtype="range:0,1000000" emptyText="万元"/>
                                    </td>
                                </tr>
                                <tr class="se_tr">
                                    <td class="se_title">所在地区：</td>
                                    <td class="se_select">
                                        {% include "element/saas/includes/input_region.html" %}
                                    </td>
                                    <td></td>
                                    <td class="se_title">主营业务：</td>
                                    <td class="se_input">
                                        <input name="OPSCOPE" class="mini-textbox" vtype="rangeLength:2,20"
                                               emptyText="关键词模糊查询">
                                    </td>
                                    <td></td>
                                    <td class="se_title">总利润：</td>
                                    <td class="se_range">
                                        <input name="total_profit1" class="mini-textbox" style="width:45%;float:left;"
                                               vtype="range:0,1000000" emptyText="万元"/>
                                        <span class="se_line">一</span>
                                        <input name="total_profit2" class="mini-textbox" style="width:45%;float:left;"
                                               vtype="range:0,1000000" emptyText="万元"/>
                                    </td>
                                </tr>
                                <tr class="se_tr">
                                    <td class="se_title">行业分类：</td>
                                    <td class="se_select">
                                        {% include "element/saas/includes/input_nic.html" %}
                                    </td>
                                    <td></td>
                                    <td class="se_title">开业日期：</td>
                                    <td class="se_range">
                                        <input name="ESDATE1" class="mini-datepicker" allowinput="false"
                                               ondrawdate="onDrawDate" style="width:45%;float:left;"/>
                                        <span class="se_line">一</span>
                                        <input name="ESDATE2" class="mini-datepicker" allowinput="false"
                                               ondrawdate="onDrawDate" style="width:45%;float:left;"/>
                                    </td>
                                    <td></td>
                                    <td class="se_title">总资产：</td>
                                    <td class="se_range">
                                        <input name="assets_re1" class="mini-textbox" style="width:45%;float:left;"
                                               vtype="range:0,1000000" emptyText="万元"/>
                                        <span class="se_line">一</span>
                                        <input name="assets_re2" class="mini-textbox" style="width:45%;float:left;"
                                               vtype="range:0,1000000" emptyText="万元"/>
                                    </td>
                                </tr>
                                <tr class="se_tr">
                                    <td class="se_title">企业状态</td>
                                    <td class="se_select">
                                        <input name="ENTSTATUS" class="mini-combobox" showNullItem="true"
                                               url="/static/element/saas/form_render/entstatus.json"/>
                                    </td>
                                    <td></td>
                                    <td class="se_title">注册资金：</td>
                                    <td class="se_range">
                                        <input name="REGCAP1" class="mini-textbox" style="width:45%;float:left;"
                                               vtype="range:0,10000000" emptyText="万元"/>
                                        <span class="se_line">一</span>
                                        <input name="REGCAP2" class="mini-textbox" style="width:45%;float:left;"
                                               vtype="range:0,10000000" emptyText="万元"/>
                                    </td>
                                    <td></td>
                                    <td class="se_title">年进口额：</td>
                                    <td class="se_range">
                                        <input name="timport1" class="mini-textbox" style="width:45%;float:left;"
                                               vtype="range:0,1000000" emptyText="万美元"/>
                                        <span class="se_line">一</span>
                                        <input name="timport2" class="mini-textbox" style="width:45%;float:left;"
                                               vtype="range:0,1000000" emptyText="万美元"/>
                                    </td>
                                </tr>
                                <tr class="se_tr">
                                    <td class="se_title">企业类型：</td>
                                    <td class="se_select">
                                        {% include "element/saas/includes/input_enttype.html" %}
                                    </td>
                                    <td></td>
                                    <td class="se_title">战兴产业分类：</td>
                                    <td class="se_select">
                                        {% include "element/saas/includes/input_elseic.html" %}
                                    </td>
                                    <td></td>
                                    <td class="se_title">年出口额：</td>
                                    <td class="se_range">
                                        <input name="texport1" class="mini-textbox" style="width:45%;float:left;"
                                               vtype="range:0,1000000" emptyText="万美元"/>
                                        <span class="se_line">一</span>
                                        <input name="texport2" class="mini-textbox" style="width:45%;float:left;"
                                               vtype="range:0,1000000" emptyText="万美元"/>
                                    </td>
                                </tr>
                                <tr class="se_tr">
                                    <td class="se_title">产业标签：</td>
                                    <td>
                                        <input name="enttags" class="mini-textbox" emptyText="敬请期待"
                                               vtype="rangeLength:2,30">
                                    </td>
                                    <td></td>
                                    <td class="se_title"></td>
                                    <td class="se_range"></td>
                                    <td></td>
                                    <td></td>
                                    <td style="text-align: center;">
                                        <a class="mini-button" plain="true" onclick="elreload()" iconCls="icon-select"
                                           style="margin-right: 30px;">清除</a>
                                        <a class="mini-button" plain="true" onclick="Adsearch()"
                                           iconCls="icon-zoomin">查找</a>
                                    </td>
                                </tr>
                            </table>
                        </form>

                        <div id="datagrid_main" class="mini-datagrid" url="/saas/company_list/?method=loadtable"
                             idField="entid" allowResize="true" multiSelect="true" showColumnsMenu="true" pageSize="20"
                             sizeList="[20,80,200,500]" virtualScroll="true">
                            <div property="columns">
                                <div type="checkcolumn"></div>
                                <div field="entid" width="50" hideable="true" visible="false">序号</div>
                                <div field="REGNO" width="120" visible="false">注册号</div>
                                <div field="ENTNAME" width="180" hideable="true">企业名称</div>
                                <div field="region_id" width="80">所在地区</div>
                                <div field="nic_id" width="120">行业分类</div>
                                <div field="elseic_id" width="120" visible="false">战兴产业</div>
                                <div field="faren" width="70">法人</div>
                                <div field="REGCAP" width="60" allowSort="true">注册资金(万)</div>
                                <div field="ENTTYPE" width="120">企业类型</div>
                                <div field="ENTSTATUS" width="60">企业状态</div>
                                <div field="ESDATE" width="75" dateFormat="yyyy-MM-dd">开业日期</div>
                                <div field="OPSCOPE" width="180" visible="false">主营业务</div>
                                <div field="enttel" width="70">企业电话</div>
                                <div field="farentel" width="70">法人电话</div>
                            </div>
                        </div>
                    </div>
                    <!--Tab 主数据表 结束-->

                    <!--Tab 子Tab-->
                    <div title="个体工商户" name="个体工商户" url="/saas/geti_list/" iconCls="icon-database_table"></div>
                </div>
            </div>
        </div>
    </div>
{% endblock %}

{% block footer_js %}
    <script type="text/javascript" src="{{ STATIC_URL }}opensource/Blob.js"></script>
    <script type="text/javascript" src="{{ STATIC_URL }}opensource/FileSaver.min.js"></script>
    <script type="text/javascript" src="{{ STATIC_URL }}opensource/xlsx.full.min.js"></script>
    <script type="text/javascript">
        mini.parse();
        var grid_main = mini.get("datagrid_main");
        var tabs = mini.get("mainTabs");
        var form_search = new mini.Form("form_search");
        top["win"] = window;
        grid_main.load();
        function Adsearch() {
            form_search.validate();
            if (form_search.isValid() == false) return;
            var sfield = 'ENTNAME￥REGNO￥region_id￥nic_id￥elseic_id￥ENTSTATUS￥ENTTYPE￥OPSCOPE'
                + '￥REGCAP￥ESDATE￥revenue￥total_profit￥assets_re￥timport￥texport';
            {#生成搜索数据#}
            var svalue = fclean(mini.getbyName("ENTNAME").getValue()) + '￥'
                + fclean(mini.getbyName("REGNO").getValue()) + '￥'
                + fclean(mini.getbyName("region_id").getValue()) + '￥'
                + fclean(mini.getbyName("nic_id").getValue()) + '￥'
                + fclean(mini.getbyName("elseic_id").getValue()) + '￥'
                + fclean(mini.getbyName("ENTSTATUS").getValue()) + '￥'
                + fclean(mini.getbyName("enttype_id").getValue()) + '￥'
                + fclean(mini.getbyName("OPSCOPE").getValue()) + '￥'
                + fclean(mini.getbyName("REGCAP1").getValue()) + '$' + fclean(mini.getbyName("REGCAP2").getValue()) + '￥'
                + fclean(mini.formatDate(mini.getbyName("ESDATE1").getValue(), "yyyy-MM-dd")) + '$'
                + fclean(mini.formatDate(mini.getbyName("ESDATE2").getValue(), "yyyy-MM-dd")) + '￥'
                + fclean(fwan(mini.getbyName("revenue1").getValue())) + '$'
                + fclean(fwan(mini.getbyName("revenue2").getValue())) + '￥'
                + fclean(fwan(mini.getbyName("total_profit1").getValue())) + '$'
                + fclean(fwan(mini.getbyName("total_profit2").getValue())) + '￥'
                + fclean(fwan(mini.getbyName("assets_re1").getValue())) + '$'
                + fclean(fwan(mini.getbyName("assets_re2").getValue())) + '￥'
                + fclean(mini.getbyName("timport1").getValue()) + '$' + fclean(mini.getbyName("timport2").getValue()) + '￥'
                + fclean(mini.getbyName("texport1").getValue()) + '$' + fclean(mini.getbyName("texport2").getValue());
            if (svalue != '￥￥￥￥￥￥￥￥$￥$￥$￥$￥$￥$￥$') {
                grid_main.load({sfield: sfield, svalue: svalue});
            }
        }

        // 筛选器的清除按钮
        function elreload() {
            grid_main.load({pageIndex: 0, pageSize: 20, sortField: " ", sortOrder: "desc"});
            form_search.clear();
        }

        function tabreload() {
            var tab = tabs.getActiveTab();
            tabs.reloadTab(tab);
        }

        function elreport(a) {
            if (!grid_main.getSelected()) {
                mini.alert("请选择一个企业（暂不支持个体户）");
            }
            else {
                var entid_value = grid_main.getSelected().entid;
                var entname_value = grid_main.getSelected().ENTNAME;
                newtab("报告: " + entname_value, '/report/' + entid_value + '/?version=' + a, 'icon-report' + a);
            }
        }

        function elreportpdf(a) {
            if (!grid_main.getSelected()) {
                mini.alert("请选择一个企业（暂不支持个体户）");
            }
            else {
                var entid_value = grid_main.getSelected().entid;
                window.open("/reportpdf/" + entid_value + '/?version=' + a);
            }
        }

        function elchart(a) {
            if (!grid_main.getSelected()) {
                mini.alert("请选择一个企业（暂不支持个体户）");
            }
            else {
                var entid_value = grid_main.getSelected().entid;
                var entname_value = grid_main.getSelected().ENTNAME;
                if (a == '2') {
                    var b = 'icon-chart_line';
                }
                else {
                    var b = 'icon-chart_organisation';
                }
                newtab("图谱: " + entname_value, '/report/' + entid_value + '/tupu/?dstyle=' + a, b);
            }
        }

        function ellifecycle() {
            if (!grid_main.getSelected()) {
                mini.alert("请选择一个企业（暂不支持个体户）");
            }
            else {
                var entid_value = grid_main.getSelected().entid;
                var entname_value = grid_main.getSelected().ENTNAME;
                newtab("生命周期: " + entname_value, '/saas/lifecycle/' + entid_value + '/', 'icon-vector');
            }
        }

        var getitab = tabs.getTab("个体工商户");
        getitab.onload = function () {
            var iframe = tabs.getTabIFrameEl(getitab);
            iframe.style.height = "800px";
        };
        // 页面json数据生成excel表
        function downloadSure() {
            mini.confirm("您将要导出本页所有数据，如需更多数据，请选择左下角显示条数或翻页。", "导出确认", function (action) {
                if (action == "ok") {
                    JSONToExcelConvertor();
                }
            });
        }
        {#导出excel#}
        function JSONToExcelConvertor() {
            var activetab = tabs.getActiveIndex();
            if (activetab == 0) {
                getdata1();
            } else {
                top["win"].getdata2();
            }
        }
        function getdata1() {
            var FileName = "企业筛查结果-{{ sitesettings.website_name }}-" + gettime();
            var JSONData = grid_main.data;
            //先转化json
            var arrData = typeof JSONData != 'object' ? JSON.parse(JSONData) : JSONData;
            var headers = {
                "ENTNAME": "企业名称", "REGNO": "注册号", "region_id": "所在地区", "nic_id": "行业分类",
                "faren": "法人", "REGCAP": "注册资金(万)", "ENTTYPE": "企业类型", "ENTSTATUS": "企业状态",
                "ESDATE": "开业日期", "OPSCOPE": "主营业务", "enttel": "企业电话", "farentel": "法人电话"
            };
            var arrKey = ["ENTNAME", "REGNO", "region_id", "nic_id", "faren", "REGCAP", "ENTTYPE", "ENTSTATUS", "ESDATE", "OPSCOPE", "enttel", "farentel"];
            if (arrData[0]["REGNO"] != "注册号") {
                arrData.unshift(headers);
            }
            if (isIEexcel()) {
                exportExcelIE(arrData, arrKey, FileName);
            } else {
                downloadExl(arrData, arrKey, FileName);
            }
        }
    </script>
    {{ block.super }}
{% endblock %}

